home *** CD-ROM | disk | FTP | other *** search
/ Super Shareware Collection / Super Shareware Collection.iso / os_2 / mwave2.zip / MWAVE.C < prev    next >
C/C++ Source or Header  |  1994-02-06  |  7KB  |  229 lines

  1. /* Output from p2c, the Pascal-to-C translator */
  2. /* From input file "mwave.pas" */
  3. /* p2c: \emx\p2c/system.imp, line 10: Warning: Symbol 'SYSTEM' was already defined [220]
  4.  * Warning: Symbol 'SYSTEM' was already defined [220] */
  5.  
  6.  
  7. #include <p2c.h>
  8.  
  9.  
  10. /*
  11.   ***************************************************************************
  12.   *                                                                         *
  13.   *            Wave maker for SoundBlaster 1.5 by HaJott                    *
  14.   *                                                                         *
  15.   ***************************************************************************
  16.     Discription of data types :
  17.  
  18.     type
  19.        chunk = record
  20.          main               : string[4];             = RIFF
  21.          main_length        : array[0..3] of byte;   = length of file
  22.          chunk_type         : string[4];             = WAVE
  23.          sub_chunk          : string[4];             = fmt_ :_=space=ASCII 32
  24.          sub_chunk_length   : array[0..3] of byte;   = always 16 bytes
  25.                                                        don't know why !
  26.          format             : word;                  = always 1 for PCM mode
  27.                               every SoundBlaster works with format = 1
  28.          modus              : word;                  1 = mono, 2 = stereo
  29.          sample_freq        : array[0..3] of byte;   11.025 kHz = $2B11
  30.                                                      22.050 kHz = $5622
  31.                                                      44.100 kHz = $AC44
  32.          bytes_per_sec      : array[0..3] of byte;   as it is
  33.          bytes_per_sample   : word;                  1 = 8 Bit, 2 = 16 Bit
  34.          bits_per_sample    : word;                  only 8, 12 or 16
  35.          data_chunk         : string[4];             = data
  36.          data_length        : array[0..3] of byte;   length of data block
  37.        end;
  38.  
  39. */
  40.  
  41. /*$N+*/
  42.  
  43. typedef unsigned short w;
  44.  
  45. typedef uchar dw[4];
  46. /*       w                  = array[0..1] of byte;*/
  47. /*       st                 = string[4]; */
  48. typedef uchar dat[16384];
  49.  
  50. typedef struct recordType {
  51.   /*st*/
  52.   dw main, main_length;
  53.   /*st*/
  54.   dw chunk_type;
  55.   /*st*/
  56.   dw sub_chunk, sub_chunk_length;
  57.   w format, modus;
  58.   dw sample_freq, bytes_per_sec;
  59.   w bytes_per_sample, bits_per_sample;
  60.   /*st*/
  61.   dw data_chunk, data_length;
  62.   dat rf;
  63. } recordType;
  64.  
  65. typedef recordType datafile;
  66.  
  67.  
  68. Static short i, j, k, maxdat;
  69. Static FILE *datei1;
  70. Static uchar ri;
  71. Static double x, stepx;
  72. Static unsigned short code;
  73. Static Anyptr p;
  74. Static short lenght;
  75. Static recordType chunk;
  76. Static short step;
  77. Static boolean bol;
  78. Static unsigned short wo;
  79. Static Char sinortri;
  80. Static Char datei1_NAME[_FNSIZE];
  81.  
  82.  
  83.  
  84. Static Void initall()
  85. {
  86.   x = 0.0;
  87.   code = 0;
  88.   i = 0;
  89.   k = 0;
  90.   j = 0;
  91.   bol = true;
  92.   chunk.main[0] = 'R';
  93.   chunk.main[1] = 'I';
  94.   chunk.main[2] = 'F';
  95.   chunk.main[3] = 'F';
  96.   chunk.main_length[0] = 45;
  97.   chunk.main_length[1] = 64;
  98.   chunk.main_length[2] = 0;
  99.   chunk.main_length[3] = 0;
  100.   chunk.chunk_type[0] = 'W';
  101.   chunk.chunk_type[1] = 'A';
  102.   chunk.chunk_type[2] = 'V';
  103.   chunk.chunk_type[3] = 'E';
  104.   chunk.sub_chunk[0] = 'f';
  105.   chunk.sub_chunk[1] = 'm';
  106.   chunk.sub_chunk[2] = 't';
  107.   chunk.sub_chunk[3] = ' ';
  108.   chunk.sub_chunk_length[0] = 16;
  109.   chunk.sub_chunk_length[1] = 0;
  110.   chunk.sub_chunk_length[2] = 0;
  111.   chunk.sub_chunk_length[3] = 0;
  112.   chunk.format = 1;
  113.   chunk.modus = 1;
  114.   chunk.sample_freq[0] = 17;
  115.   chunk.sample_freq[1] = 43;
  116.   chunk.sample_freq[2] = 0;
  117.   chunk.sample_freq[3] = 0;
  118.   chunk.bytes_per_sec[0] = 68;
  119.   chunk.bytes_per_sec[1] = 172;
  120.   chunk.bytes_per_sec[2] = 0;
  121.   chunk.bytes_per_sec[3] = 0;
  122.   chunk.bytes_per_sample = 4;
  123.   chunk.bits_per_sample = 8;
  124.   chunk.data_chunk[0] = 'd';
  125.   chunk.data_chunk[1] = 'a';
  126.   chunk.data_chunk[2] = 't';
  127.   chunk.data_chunk[3] = 'a';
  128.   chunk.data_length[0] = 0;
  129.   chunk.data_length[1] = 40;
  130.   chunk.data_length[2] = 0;
  131.   chunk.data_length[3] = 0;
  132.   for (j = 1; j <= 16384; j++)
  133.     chunk.rf[i - 1] = 0;
  134. }
  135.  
  136.  
  137. main(argc, argv)
  138. int argc;
  139. Char *argv[];
  140. {
  141.   short FORLIM, FORLIM1;
  142.  
  143.   PASCAL_MAIN(argc, argv);
  144.   datei1 = NULL;
  145.   initall();
  146.   printf("\n Wave maker for SoundBlaster 1.5 by HaJott \n\n");
  147.   printf(" Enter number in () to create wave \n");
  148.   printf("Pulse wave (2), Sinus wave (1), triangle wave (0) : ");
  149.   scanf("%c%*[^\n]", &sinortri);
  150.   getchar();
  151.   switch (sinortri) {
  152.  
  153.   case '1':
  154.     stepx = 0.4;
  155.     /**** stepx makes the frequency, 0.4=low 0.8=high ****/
  156.     printf("\nMake Sinus \n");
  157.     for (i = 1; i <= 16384; i++) {
  158.       chunk.rf[i - 1] = labs((long)floor(127 + 127 * sin(x) + 0.5));
  159.       /*this makes a sinus wave between 0 and 254 (8bit)*/
  160.       x += stepx;
  161.     }  /*for i:=1 to 16384 do*/
  162.     break;
  163.  
  164.   case '2':   /*makes a triangle wave between 0 an 254 (8bit)*/
  165.     i = 0;
  166.     step = 16;
  167.     /**** step makes the frequency, step=64 means low step=16 high*/
  168.     maxdat = 16384 / (step * 2);
  169.     printf("\nMake Pulse \n");
  170.     FORLIM = maxdat;
  171.     for (k = 1; k <= FORLIM; k++) {
  172.       FORLIM1 = step;
  173.       for (j = 1; j <= FORLIM1; j++) {
  174.     i++;
  175.     chunk.rf[i - 1] = 0;
  176.       }
  177.       FORLIM1 = step;
  178.       for (j = 1; j <= FORLIM1; j++) {
  179.     i++;
  180.     chunk.rf[i - 1] = 255;
  181.       }
  182.       /**** makes a pulse wave between 0 and 255 (8bit) ****/
  183.     }  /*for k:=1 to 256 do*/
  184.     break;
  185.  
  186.   default:
  187.     printf("\nMake Triangle \n");
  188.     step = 8;   /*step makes the frequency, step=8 means low step=16 high*/
  189.     while (i <= 16384) {
  190.       if (chunk.rf[i - 1] >= 255 - step) {
  191.     step = -step;
  192.     bol = false;
  193.       }
  194.       if (chunk.rf[i - 1] <= step) {
  195.     step = abs(step);
  196.     bol = true;
  197.       }
  198.       i++;
  199.       chunk.rf[i - 1] = chunk.rf[i - 2] + step;
  200.     }
  201.     break;
  202.   }/*case*/
  203.  
  204.   printf("Size of complete Datafile : %ld\n", sizeof(recordType));
  205.   printf("Size of wave data : %ld\n", sizeof(dat));
  206.   chunk.main_length[0] = (sizeof(recordType)) & 255;
  207.   chunk.main_length[1] = ((unsigned long)(sizeof(recordType))) >> 8;
  208.   chunk.data_length[0] = (sizeof(dat)) & 255;
  209.   chunk.data_length[1] = ((unsigned long)(sizeof(dat))) >> 8;
  210.   strcpy(datei1_NAME, "c:\\mmos2\\sounds\\aaa.wav");
  211.   if (datei1 != NULL)
  212.     datei1 = freopen(datei1_NAME, "w+b", datei1);
  213.   else
  214.     datei1 = fopen(datei1_NAME, "w+b");
  215.   if (datei1 == NULL)
  216.     _EscIO(FileNotFound);
  217.   fwrite(&chunk, sizeof(recordType), 1, datei1);
  218.   if (datei1 != NULL)
  219.     fclose(datei1);
  220.   datei1 = NULL;
  221.   if (datei1 != NULL)
  222.     fclose(datei1);
  223.   exit(EXIT_SUCCESS);
  224. }
  225.  
  226.  
  227.  
  228. /* End. */
  229.